<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;
// use App\models\User;
class LoginController extends Controller
{
     public function index()
    {
		 return view('home.index');
    }

    public function gologin()
    {
       return view('home.login');     
    }
     
     public function dologin(Request $request)
     {
		//dd($request);
        $name=$request->input('name');
		//dd($name);
        $ob=DB::table('user')->where('name',$name)->first();
		//dd($ob);
        if($ob){
          if($request->input('password') == $ob->password){
               session(['homeuser' => $ob]);
               return  redirect('home');
          }else{
            return back()->with('msg','登录失败，密码错误'); 
          } 
        }else{
              return back()->with('msg','登录失败，账号不存在'); 
        }
     }
 
    public function loginhomeout()
    {
         session()->forget('homeuser');
         return redirect('home/login');
    }

      public function goregister()
      {
       return view('home.register');     
      }
	  public function doregister(Request $request)
	  {
		$data = $request->except('_token');
		//dd($data);
        $m = DB::table('user')->insertGetId($data);
        if($m>0){
            return  redirect('/home/gologin');
        }else{
            return  redirect('/home/goregister');
        }
	  }
}
